<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function find2smallest(arr) {
            let first = Number.MAX_VALUE;
            let second = Number.MAX_VALUE;
            let i;
            if (arr.length < 2) {
                console.log("数组中至少包含两个数");
                return;
            }
            for (i = 0; i < arr.length; i++) {
                if (arr[i] < first) {
                    second = first;
                    first = arr[i];

                }
                if (arr[i] < second && arr[i] !== first) {
                    second = arr[i];


                }
            }
            if (second === Number.MAX_VALUE) {
                console.log('没有第二小的数值');
                console.log("first:" + first);
            } else {
                console.log("first:" + first);
                console.log("second:" + second);

            }
        }
        let arr = [-1, -2, 33, 4, -5, 6, 7, -333, 455, 65];
        find2smallest(arr);
    </script>
</body>

</html>